package com.master.common.baseService.message;

import com.master.constant.model.SysMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Heath.Que
 * @version 1.0
 * @classname SendMessageService
 * @description TODO
 * @Date 2021/6/4 14:11
 **/
@Component
public class SendMessageService {

    private final static Logger logger = LoggerFactory.getLogger(SendMessageService.class);

    @Autowired
    RabbitTemplate rabbitTemplate;//使用RabbitTemplate,这提供了接收/发送等等方法

    /**
     * @Description: 按传入的队列类型、路由类型、消息体发送消息
     * @Parameter: [message, queueType, routingType]
     * @Return: java.lang.Boolean
     * @author: Heath.Que
     * @Date: 2021/6/4
     **/
    public Boolean sendDirectMessage(SysMessage message, String queueType, String routingType) {
        boolean mark = false;
        try {
            //将消息放入队列
            rabbitTemplate.convertAndSend(queueType, routingType, message.getMessageContent());
            mark = true;
        }catch (Exception e){
            logger.error(e.getMessage());
        }

        return mark;
    }
}
